# @Filename:    sample1
# @Author:      王佳伟
# @Time:        2025-02-25 16:56
# @Describe:    数据库测试
import pymysql

def connect_to_database(host, user, password, database):
    conn = pymysql.connect(host=host, user=user, password=password, database=database)
    return conn

def execute_sql_query(conn, sql_query):
    cursor = conn.cursor()
    cursor.execute(sql_query)
    result = cursor.fetchall()
    cursor.close()
    return result

if __name__ == '__main__':
    db_conn = connect_to_database('localhost', 'root', '123', 'mall')
    result = execute_sql_query(db_conn, 'SELECT * FROM cms_subject')
    print(result)
    db_conn.close()